<?php
/**
 * 活动
 * User: E 房cms www.fangcms.com
 * Date: 2015/1/20
 * Time: 10:51
 */
namespace Home\Controller;
use Org\Yike\FangCms;
use Org\Util\Page;
class ActivityController extends CommonController{
    public function _initialize(){
        parent::_initialize();
        $this->activity_cate = M('activity_cate')->where(array('status'=>1,'pid'=>0))->order('ordid desc')->limit(15)->select();
    }

    public function index(){
        $where = array('status'=>1,'img'=>array('neq',''));
        $count = M('activity')->where($where)->count();
        $pager = new Page($count, 8);
        $this->list = M('activity')->where($where)->limit($pager->firstRow.','.$pager->listRows)->order('ordid desc,id desc')->select();
        $this->page = $pager->show();
        $this->display();
    }

    public function lists(){
        $FangCms = new FangCms();
        $alias = I('get.alias');
        if(!$alias){
            $this->error('找不到对应的分类名称');
        }

        $cate = M('activity_cate')->where(array('status'=>1,'alias'=>$alias))->find();

        $this->cate_nav = $FangCms->currentLocation('activity_cate',array('status'=>1,'id'=>$cate['id']));

        $cate_ids = $FangCms->getCate('activity_cate',4,array('pid'=>$cate['id']));
        array_push($cate_ids,$cate['id']);

        //按条件查询
        $where = array('a.status'=>1,'a.cate_id'=>array('in',implode(',',$cate_ids)));
        $this->page_arr = $FangCms->getActivityList(18,$where,true);
        $this->alias = $alias;
        $this->cate = $cate;
        $this->seoKey($cate,'name');
        $this->display();
    }

    //问答详细
    public function detail(){
        $FangCms = new FangCms();
        $id = intval($_GET['id']);
        if(!$id){
            $this->error('没有找到对应ID信息');
        }
        $info = M('activity')->where(array('id'=>$id,'status'=>1))->find();
        if(!$info['id']){
            $this->error('没有找到对应ID信息');
        }
        $FangCms->setInc($id,'activity');

        //当前位置
        $this->cate_nav = $FangCms->currentLocation('activity_cate',array('status'=>1,'id'=>$info['cate_id']));

        $this->cate = M('activity_cate')->where(array('id'=>$info['cate_id']))->find();
        //热门排行
        $this->activity_hits = M('activity')->where(array('status'=>1))->limit(10)->order('hits desc')->select();
        //相关资讯
        $this->rec_list = M('activity')->where(array('status'=>1,'cate_id'=>$info['cate_id'],'id'=>array('gt',$info['id'])))->order('id asc')->limit(6)->select();

        $this->info = $info;
        $this->seoKey($info,'title');
        $this->display();
    }



}